package com.ycc.biz.controller;

import com.ycc.biz.pojo.entity.BizAttachment;
import com.ycc.biz.pojo.entity.BizBuyer;
import com.ycc.biz.pojo.entity.SysUser;
import com.ycc.biz.service.BizBuyerService;
import com.ycc.biz.service.BizAttachmentService;
import com.ycc.biz.common.Result;
import com.ycc.biz.pojo.query.BizBuyerQuery;
import com.ycc.biz.pojo.vo.BizBuyerVO;
import com.ycc.biz.common.PageResult;
import com.ycc.biz.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.ycc.biz.constant.UserConstant.USER_LOGIN_STATE;

/**
 * @ClassName: BizBuyerController
 * @author: ycl
 * @date: 2025/03/14 14:55:20
 */
@Api(tags = "买家管理")
@RestController
@RequestMapping("/buyer")
@AllArgsConstructor
public class BizBuyerController {
    private final BizBuyerService bizBuyerService;

    @ApiOperation("添加买家")
    @PostMapping("/addBuyer")
    public Result<Boolean> addBuyer(@ApiParam("买家信息") @RequestBody BizBuyer buyer, HttpServletRequest request) {
        return Result.success(bizBuyerService.addBuyer(buyer, request));
    }

    @ApiOperation("删除买家")
    @PostMapping("/deleteBuyer")
    public Result<Boolean> deleteBuyer(@RequestParam String id) {
        return Result.success(bizBuyerService.removeById(id));
    }

    @ApiOperation("更新买家")
    @PostMapping("/updateBuyer")
    public Result<Boolean> updateBuyer(@ApiParam("买家信息") @RequestBody BizBuyer buyer) {
        return Result.success(bizBuyerService.updateById(buyer));
    }

    @ApiOperation("根据ID查询买家")
    @PostMapping("/getBuyerById")
    public Result<BizBuyer> getBuyerById(@RequestParam String id) {
        return Result.success(bizBuyerService.getById(id));
    }

    @ApiOperation("查询所有买家")
    @PostMapping("/listBuyers")
    public Result<List<BizBuyer>> listBuyers() {
        return Result.success(bizBuyerService.list());
    }
    
    @ApiOperation("分页查询买家")
    @PostMapping("/pageBuyers")
    public Result<PageResult<BizBuyerVO>> pageBuyers(@RequestBody BizBuyerQuery query) {
        return Result.success(bizBuyerService.pageBuyers(query));
    }
}
